﻿package com.grts.mall;

import java.io.FileWriter;
import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import com.fasterxml.jackson.databind.ObjectMapper;

/* *
 *类名：AlipayConfig
 *功能：基础配置类
 *详细：设置帐户有关信息及返回路径
 *修改日期：2017-04-05
 *说明：
 *以下代码只是为了方便商户测试而提供的样例代码，商户可以根据自己网站的需要，按照技术文档编写,并非一定要使用该代码。
 *该代码仅供学习和研究支付宝接口使用，只是提供一个参考。
 */
@Component
public class AlipayConfig implements CommandLineRunner {

//↓↓↓↓↓↓↓↓↓↓请在这里配置您的基本信息↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

	// 应用ID,您的APPID，收款账号既是您的APPID对应支付宝账号
	public static String app_id = "2021000116687069";

	// 商户私钥，您的PKCS8格式RSA2私钥
	public static String merchant_private_key = "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCAVe2M3tQOztk5zkZxZcaG1hU167p5a98vFehF0FloVHKxPnTV1m/sJ1KGtmyTkmZcA1YUiKGsetKkb5dmv05S7WVrTzFAIY7hBO6sZ21vaRByLmLxFXI6YfA4j/NzgoSy0b89qrumMZLPyX3diRDhGovthnODYCD3zlv9omWetDI0i/jRHTXb3pXzWg8UIYaWXf45UvVBcul1d3gs95sch5SDWYfQe80JH0/78NxcqItIsPMJrBJlcFfPd9aExnyo0bzOPOoTYvEEB6NAV1C0NheoUwUSb8PBtBlJR7ptfvAM4JaOP7VXgbz+1jQSmrvR8WWNI2Fczpj3U0exy9mNAgMBAAECggEAHPvLD4KPn9yFYLG+ZQPYR0F4PtpDHgMHv6mR8JpyZsaTtIXnexfX5RyoXbY7ZUSuC1/RhAerg7mlcu+k4NaZyM7Gleqns9UgYJ9ti9A7/epbhX4GaG4wgxD1YMDZ+Z9jesM2DqZNhOYzQuw9mdfH0R7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看地址：https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
	public static String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxajsvqthYb0+V02IRUeqJTEu3/NTpTn/ydXCXORLQ2fOeaoAKlw03aGlAsdVHogDoYvEu7LOD9Bp+493/Hqlwn4yE2WwN2DkpcPnxjhtXt9bx+r9cBZqRiqATLCe9hP3NLMZ5m3aN1V7u+StnzMygnEHs4i9ZP+gWYJQmMIiqQ8kRt9CI9RJKfxLrgahvTmIq8YwzKewy3eR/WlU+23ymqONspYk8MhUqb10T5i0vT7L5Kez1WvwXMX6SWmw+nn4RMgaN91CaHHk5vYCRKXHQH/V3Vbdzn6VCwh9VSHlXHJxr4FHSZpwjiEy73uzP6IaukiTR01RS0D9hiSmueqJLwIDAQAB";

	// 服务器异步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
	public static String notify_url = "";

	// 页面跳转同步通知页面路径 需http://格式的完整路径，不能加?id=123这类自定义参数，必须外网可以正常访问
	public static String return_url = "http://localhost:8082/finalyhandler";

	// 签名方式
	public static String sign_type = "RSA2";

	// 字符编码格式
	public static String charset = "utf-8";

	// 支付宝网关
	public static String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";

	// 支付宝网关
	public static String log_path = "C:\\";

//↑↑↑↑↑↑↑↑↑↑请在这里配置您的基本信息↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑

	/**
	 * 写日志，方便测试（看网站需求，也可以改成把记录存入数据库）
	 * 
	 * @param sWord 要写入日志里的文本内容
	 */
	public static void logResult(String sWord) {
		FileWriter writer = null;
		try {
			writer = new FileWriter(log_path + "alipay_log_" + System.currentTimeMillis() + ".txt");
			writer.write(sWord);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			if (writer != null) {
				try {
					writer.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}


	@Override
	public void run(String... args) throws Exception {
		Config options = new Config();
		options.protocol = "https";
		options.gatewayHost = "openapi.alipaydev.com";
		options.signType = "RSA2";
		options.appId = app_id;
		options.merchantPrivateKey = merchant_private_key;
		options.alipayPublicKey = alipay_public_key;
		Factory.setOptions(options);

	}
}
